#include "string.h"
#include "TypedValue.h"
#include "include.h"

TypedValue::TypedValue(void * value, char * type)
{
	this->value = value;
	strcpy(this->type, type);
}
void * TypedValue::GetValue()
{
	return value;
}
char * TypedValue::GetType()
{
	return type;
}	
bool TypedValue::IsEqual(int i)
{
	if(IsInt())
	{
		return *((int *)value) == i;
	}
	
	if(IsFloat())
	{
		return *((float *)value) == i;
	}
	return false;
}
bool TypedValue::IsEqual(float f)
{
	if(IsInt())
	{
		return *((int *)value) == f;
	}
	
	if(IsFloat())
	{
		return *((float *)value) == f;
	}
	return false;
}
bool TypedValue::IsEqual(char * string)
{
	if(IsString())
	{
		return strcmp((char *)value, string) == 0;
	}
	return false;
}
bool TypedValue::IsBoolean()
{
	return strcmp(type, BOOL_TYPE_STRING) == 0;
}
bool TypedValue::IsInt()
{
	return strcmp(type, INT_TYPE_STRING) == 0;
}
bool TypedValue::IsFloat()
{
	return strcmp(type, FLOAT_TYPE_STRING) == 0;
}
bool TypedValue::IsString()
{
	return strcmp(type, STRING_TYPE_STRING) == 0;
}
bool TypedValue::operator==(TypedValue other)
{
	if(strcmp(type, other.GetType()) == 0)
	{
		if(IsBoolean())
		{
			return *((bool *)value) == *((bool *)other.GetValue());
		}
		if(IsInt())
			return *((int *)value) == *((int *)other.GetValue());
		if(IsFloat())
			return *((float *)value) == *((float *)other.GetValue());
		if(IsString())
			return strcmp((char*)value, (char *)other.GetValue()) == 0;
	}
	return false;
}